package com.situ.controller.cst_service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.entity.might.SysMight;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.entity.bas_dict.BasDict;
import com.situ.entity.customer.CstCustomer;
import com.situ.entity.might.SysMight;
import com.situ.entity.user.SysUser;
import com.situ.service.bas_dict.BasDictService;
import com.situ.service.customer.CstCustomerService;
import com.situ.service.user.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.situ.service.cst_service.CstServiceService;
import com.situ.entity.cst_service.CstService;
import com.situ.util.*;

import java.util.List;

/**
 * CstService的路由接口服务
 * 
 * @author胡文
 *
 */
//
@RestController
public class CstServiceController {

	/** CstServiceService服务 */
	@Autowired
	private CstServiceService cstServiceService;

	/**
	 * 查询所有CstService数据的方法
	 * @param value
	 * @return
	 */
	@RequestMapping(value = "/CstService/query", produces = {"application/json;charset=UTF-8"})
	public ResponseData query(CstService value) {

		return ResponseData.ok().putDataValue("list",cstServiceService.find(value));
	}

	/**
	 * 通过id查询CstService数据的方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "/CstService/queryById/{id}", produces = {"application/json;charset=UTF-8"})
	public ResponseData queryById(@PathVariable(name="id") Long id) {
		 return ResponseData.ok().putDataValue("obj",cstServiceService.findOne(id));
	}
	
	/**
	 * 插入CstService属性不为空的数据方法
	 *
	 * @return
	 */
	@RequestMapping(value = "/CstService/save")
	public ResponseData save(CstService value) {
		return ResponseData.ok().putDataValue("obj", cstServiceService.saveNotNull(value));
	}
	
	/**
	 * 更新CstService属性不为空的数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "/CstService/update", produces = {"application/json;charset=UTF-8"})
	public ResponseData update(CstService value) {
		return ResponseData.ok().putDataValue("obj",cstServiceService.updateNotNullById(value));
	}

	/**
	 * 通过id删除CstService数据方法
	 *
	 * @return
	 */
	@RequestMapping(value = "/CstService/delById/{id}", produces = {"application/json;charset=UTF-8"})
	public ResponseData delById(@PathVariable(name="id") Long id) {
		return ResponseData.ok().putDataValue("obj",cstServiceService.deleteById(id));
	}


    //带分页的查询全部
//@ApiOperation("带分页的查询全部")

    @RequestMapping(value = "/CstService/queryPage", produces = {"application/json;charset=UTF-8"})
    public ResponseData queryPage(CstService value,
                                  @RequestParam(defaultValue = "1",required = false) int pageNum ,
                                  @RequestParam(defaultValue = "5",required = false) int pageSize) {

        PageHelper.startPage(pageNum, pageSize);
        List<CstService> list = cstServiceService.queryBylike(value);
        PageInfo pageInfo = new PageInfo<CstService>(list, 5);

        return ResponseData.ok()
                // .putDataValue("list", list)
                .putDataValue("pageInfo", pageInfo);
        }


//    @RequestMapping(value = "/CstService/queryPage", produces = {"application/json;charset=UTF-8"})
//    public ResponseData queryPage(String value) {
//        List list = cstServiceService.find2(value);
//
//        return ResponseData.ok().putDataValue("list", list);
//    }
//



//    @RequestMapping(value = "/CstService/queryPage", produces = {"application/json;charset=UTF-8"})
//    public ResponseData queryPage(String value) {
//        List list = cstServiceService.find2(value);
//        String id="21";
//        return ResponseData.ok().putDataValue("list", list);
//    }

     //根据id删除服务
     @RequestMapping("/CstService/delById/{id}")
     public String delById2(@PathVariable Long id) {
         cstServiceService.deleteById(id);
         return "删除成功";
         }


         //服务处理
    @RequestMapping("/CstService/updatedeal")
    public String updatedeal(CstService value){
        cstServiceService.updatedeal(value);
        return "处理成功";
    }

    @RequestMapping("/CstService/updatedetail")
    public String updatedetail(CstService value){
        cstServiceService.updatedetail(value);
        return "处理成功";
    }

    @RequestMapping("/CstService/updateservice")//分配给谁谁谁 q
    public  String updateservice(CstService value){
        cstServiceService.updatecreate(value);
        return "分配成功";
    }
}
